import { defineStore } from 'pinia'
import search from '@/api/search'
import type { DefaultKeywordData, HotKeywordVOListData, SearchAutoData } from '@/api/search'
interface SearchStoreStateData {
  defaultKeyword: DefaultKeywordData
  defaultKeywords: DefaultKeywordData[]
  hotKeywordVOList: HotKeywordVOListData[]
  searchAutoData: string[]
  searchDetailData: any
  text: any
}
export const userSearchStore = defineStore('search', {
  state(): SearchStoreStateData {
    return {
      defaultKeyword: {
        keyword: '',
        schemeUrl: '',
        highlight: '',
        hidden: '',
        type: '',
        algSort: '',
        extra: {
          resource: {
            materialName: '',
            resourcesId: '',
            materialId: ''
          }
        }
      },
      defaultKeywords: [],
      hotKeywordVOList: [],
      searchAutoData: [],
      searchDetailData: {},
      text: [
        { id: 1, name: 2 },
        { id: 1, name: 2 },
        { id: 1, name: 2 },
        { id: 1, name: 2 },
        { id: 1, name: 2 },
        { id: 1, name: 2 },
        { id: 1, name: 2 },
        { id: 1, name: 2 },
        { id: 1, name: 2 }
      ]
    }
  },
  actions: {
    async getSearchData() {
      const res = await search.getSearchKeywordData()
      this.defaultKeyword = res.data.defaultKeyword
      this.defaultKeywords = res.data.defaultKeywords
      this.hotKeywordVOList = res.data.hotKeywordVOList
    },
    async getSearchAutoData(params: string) {
      const res = await search.getSearchAutoData(params)

      this.searchAutoData = res.data
    },
    async getSearchDetailData(params: string) {
      const res = await search.getSearchDetailData(params)

      this.searchDetailData = res.data
    }
  },
  getters: {}
})
